const ActionButton = (hook, {
	Button,
	Tooltip,
	Dropdown,
	Popconfirm,
	throttle2
}) => {
	return {
		isJiess: true,
		name: 'ActionButton',
		setup({
			items,
			onClick,
			tip = '',
			pop = '',
			icon = null,
			text = null,
			// 默认阻止冒泡
			stop = true,
			// 节流时长
			waitTime = 500,
			tipParam = {},
			popParam = {},
			...other
		}) {
			const initButton = (param) => {
				const config = {
					onClick: e => {
						if (stop) e.stopPropagation();
						// 有浮框，则不绑定处理事件
						if (pop) return;
						// 对按钮默认启用节流功能
						if (typeof onClick === 'function') {
							throttle2(onClick, waitTime);
						}
					},
					...param,
					...other
				};
				if (Array.isArray(items)) {
					config.is = Dropdown.Button
					config.items = Dropdown.items
				} else {
					config.is = Button
				}
				if (text) {
					config.children = text;
				} else if (icon) {
					config.icon = icon
					config.shape = 'circle';
				}
				return config;
			};
			// antd中，tip与pop无法共存
			this.add(pop ? {
				title: pop,
				is: Popconfirm,
				// 使用浮框确认
				onConfirm: onClick,
				'okText': '确定',
				'cancelText': '取消',
				children: initButton(),
				...popParam,
			} : tip ? {
				title: tip,
				is: Tooltip,
				children: initButton(),
				...tipParam,
			} : initButton());
		}
	}
}
export default ActionButton;